package com.adu.demo.controller;
import com.adu.demo.domain.Book;
import com.adu.demo.service.Impl.BookService;
import com.adu.demo.util.JsonResult;
import com.adu.demo.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
// 测试
@RestController
@RequestMapping("/Book")
public class BookController extends BaseController {
    @Autowired
    private BookService bookService;

    @GetMapping("/getList")
    public Result getList(@RequestBody Book book){
        startPage();
        List<Book> bookList=bookService.getList(book);
        return JsonResult.OK(200,"success",bookList);
    }

    @GetMapping("/getById")
    public Result getById(Long id){
        Book book=bookService.getById(id);
        return JsonResult.OK(200,"success",book);
    }
    @PostMapping("/save")
    public Result save(@RequestBody Book book){
        bookService.save(book);
        return JsonResult.OK(200,"success");
    }
    @DeleteMapping("/removeBatch")
    public Result remove(@PathVariable Long[] ids){
        bookService.deleteByIds(ids);
        return JsonResult.OK(200,"success");
    }
    @DeleteMapping("/remove")
    public Result remove(@PathVariable Long id){
        bookService.deleteById(id);
        return JsonResult.OK(200,"success");
    }
    @GetMapping("/update")
    public Result update(@RequestBody Book book){
        bookService.update(book);
        return JsonResult.OK(200,"success");
    }
}